{extend name="base/base" /}
{block name="main"}
<style>
    .layui-form-pane .layui-form-label{width: 130px;}
    .layui-form-pane .layui-input-block{
        margin-left: 130px;
    }
    td{    height: 30px;
        line-height: 30px;}
    table tr th{    text-align: center;font-weight: 600;}
    .layui-table td, .layui-table th{    padding: 0px 0px;text-align: left; }
    .layui-table td, .layui-table th{font-size:8px}
</style>
    <div class="layui-form-item">
        <div class="">
            <a class="layui-btn" href="{:url('/admin/shijuan-list')}">返回</a>
            <span style="display: inline-block;margin-left: 50px;"></span>{$title}</span>
        </div>
    </div>
{if isset($list)}


<form id="form" method="post" class="layui-form layui-form-pane" action="{:url('/admin/shijuan-manageedit')}">
<div class="layui-form-item">
    <table class="layui-table" style="width: 100%;text-align: center;margin-top: 20px;">
        <tr><th style="text-align:center;width:50px;font-weight:600;">题目ID</th>
            <th style="text-align:center;font-weight:600;">题目</th>
            <th style="text-align:center;width:200px;font-weight:600;">排序</th>
            <th style="text-align:center;width:100px;font-weight:600;">删除</th>
        </tr>
        {volist name="list" id="vo"}
        <tr>
            <td style="text-align:center;">{$vo['id']}</td>
            <td style="text-align:center;">{$vo['title']}</td>
            <td style="text-align:center;">
                <input type="hidden" name="info[{$key}][id]" value="{$vo['id']}">
                <input name="info[{$key}][sort]" value="{$vo['sort']}"></td>
            <td style="text-align:center;"><a href="javascript:void(0)" class="del" url="{$vo['id']}">删除</a></td>
        </tr>
        {/volist}
    </table>
</div><br>

<div class="layui-form-item">
    <div class="layui-input-block" style="margin-bottom:55px">
        <input type="hidden" name="s_id" value="{:isset($s_id)?$s_id:''}">
        <input type="hidden" name="__token__" id="token" value="{$Request.token}"/>
        <button class="layui-btn" lay-submit lay-filter="*">保存</button>
        <button class="layui-btn" style="display:none;" lay-submit lay-filter="px_btn">一键排序</button>
    </div>
</div>
</form>

{/if}


{/block}
{block name="script"}
{css href="/form-select/formSelects-v4.css" /}
<script>
    layui.config({
        base: '/form-select/' //此处路径请自行处理, 可以使用绝对路径
    }).extend({
        formSelects: 'formSelects-v4'
    });
    layui.use(['form', 'jquery', 'formSelects','upload'], function () {
        var formSelects = layui.formSelects, form = layui.form, $ = layui.jquery,upload = layui.upload;

        //上传文件
        upload.render({
            elem: '.fileBtn',
            url: "{:url('/admin/upload_excel')}",
            type:'file',
            accept:'file',
            exts: 'xlsx',
            multiple: false,
            auto: true,//是否自动上传，true自动上传,false手动上传

            done: function(data){
                var icon=5;
                if(!data.code){
                    icon=6;
                    $('#fileUrl').val(data.data.url);
                }
                layer.msg(data.msg, {icon:icon,time: 1500});
            },
            error: function(){
                layer.msg('上传失败', {icon:icon,time: 1500});
            }
        });

        $(".del").on("click",function(){
            var id = $(this).attr('url');
            var s_id = "{$s_id}";
            layer.confirm('确定删除操作？',{icon:3, title:'提示信息'},function(index){
                $.post("{:url('/admin/shijuan-managedel')}",{id:id,s_id:s_id},function(data){
                    var icon=5;
                    if(data.code){
                        icon=6;
                    }
                    layer.msg(data.msg, {icon:icon,time: 1500}, function () {
                        if(data.code){
                            location.reload();
                        }
                    });
                })
            });
        });

        // $("#dosave").click(function(){
        //     var obj = $(this);
        //     obj.attr("disabled", "disabled").addClass("layui-disabled");
        //     $("#form")
        //     $.post("{:url('/admin/bianma-alladd')}",{bian_id:bian_id},function(data){
        //         if(data.code){
        //             layer.msg(data.msg, {icon: 6, time: 1500}, function () {   //提示的插件，可以使用alert代替
        //                 setTimeout(function () {
        //                     //刷新父页面
        //                     //parent.location.reload();
        //                     location.href=data.url;
        //                 }, 500);
        //
        //             });
        //         }else{
        //             layer.msg(data.msg);
        //             obj.removeAttr("disabled").removeClass("layui-disabled");
        //         }
        //     })
        // });

        formSelects.on('selectId', function (id, vals, val, isAdd, isDisabled) {
            $('#group_id').val(layui.formSelects.value(id, 'val'));
        }, true);
        //表单验证
        form.verify({

        });
        //表单提交
        form.on("submit(*)", function (data) {
            console.log(data.field)
            var obj = $(this);
            obj.attr("disabled", "disabled").addClass("layui-disabled");
            $.post(data.form.action, data.field, function (data) {
                var icon = 5;
                if (data.code) {
                    icon = 6;
                }
                layer.msg(data.msg, {icon: icon, time: 1500}, function () {   //提示的插件，可以使用alert代替
                    if (data.code) {
                        setTimeout(function () {
                            location.href=data.url;
                        }, 500);
                    } else {
                        $('#token').val(data.data.token);
                        obj.removeAttr("disabled").removeClass("layui-disabled");
                    }
                });
            }, 'json');
            return false;
        });
        form.on("submit(px_btn)", function (data) {
            console.log(data.field)
            var obj = $(this);
            obj.attr("disabled", "disabled").addClass("layui-disabled");
            $.post("{:url('/admin/shijuan-managesort')}", data.field, function (data) {
                var icon = 5;
                if (data.code) {
                    icon = 6;
                }
                layer.msg(data.msg, {icon: icon, time: 1500}, function () {   //提示的插件，可以使用alert代替
                    if (data.code) {
                        setTimeout(function () {
                            location.href=data.url;
                        }, 500);
                    } else {
                        $('#token').val(data.data.token);
                        obj.removeAttr("disabled").removeClass("layui-disabled");
                    }
                });
            }, 'json');
            return false;
        });
    });


</script>
{/block}